<%
String encode="jpeg";
String uri=request.getRequestURI();
String myurl="http://"+request.getHeader("Host")+uri.substring(0,uri.length()-19); //19 ist the length of my page name
String dataFile="realtime.txt";
response.setContentType("image/"+encode);
response.setDateHeader ("Expires",0);


// create Chart from data file
com.java4less.rchart.ChartLoader loader=new com.java4less.rchart.ChartLoader();
loader.loadFromFile(myurl+dataFile,false);

// create chart

// set initial valu of the X Axis based on the time
java.util.Date now=java.util.Calendar.getInstance().getTime();
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("dd/MM/yy hh:mm:ss");

loader.setParameter("XAXIS_INITIAL_DATE",formatter.format(now));


// create random data based on the time
java.util.Calendar cal=java.util.Calendar.getInstance();
String data1="";
String data2="";
for (int i=0;i<9;i++) {		
	cal.add(java.util.Calendar.SECOND,-2);
	if (data1.length()>0) data1="|" + data1;
	data1=""+cal.get(java.util.Calendar.SECOND)+ data1;
	if (data2.length()>0) data2="|" + data2;
	data2=""+(cal.get(java.util.Calendar.SECOND)/6)+ data2;		
}


loader.setParameter("SERIE_DATA_1",data1);
loader.setParameter("SERIE_DATA_2",data2);


// get output stream
java.io.OutputStream outb=response.getOutputStream();

	
// size of the chart image		   
int w=500;
int h=500;


com.java4less.rchart.Chart chart=loader.build(false,false);

// set size of the chart
chart.setSize(w,h);

// encode image and send output to the browser
chart.saveToFile(outb,encode);			
outb.close();


%>